import { Component, OnInit } from '@angular/core';
import { HeroService } from '../../../services/hero.service';
import { StorageService } from '../../../services/storage.service';
import { NzMessageService,NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-maintlist',
  templateUrl: './maintlist.component.html',
  styleUrls: ['./maintlist.component.css']
})
export class MaintlistComponent implements OnInit {

  loading = true;
  btn_loading=false;
  public name:string='';
  public mobile:string='';
  public isJoinOrg:string='';
  public status:string='';
  public type:string='';
  public childValue:number;
  public isVisible:boolean=false;
  public maintlist:Array<any>=[];
  public connectMaint:Array<any>=[];
  public PageIndex:number=1;
  public PageSize:number=10;
  public PageTotal:number;
  constructor(private heroService: HeroService,
              private message: NzMessageService,
              private modalService: NzModalService,
              private storageService: StorageService) { }

  ngOnInit() {
    this.getTenantlist();
  }

  //获取维修员列表数据
  getTenantlist(){
    this.btn_loading=true;
    let url=host+"/main/merchantConnectMaint/list";
    let model="nameLike="+this.name+"&mobileLike="+this.mobile+"&isJoinOrg="+this.isJoinOrg+"&Status="+this.status+"&type="+this.type+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    this.heroService.post(url,model).then(result=>{
      this.btn_loading=false;
      if(result.code==0){
        this.maintlist=result.data.pageBean.result;
        this.connectMaint=result.data.connectMaint;
        this.PageIndex=result.data.pageBean.curPage;  
        this.PageTotal=result.data.pageBean.totalRow;
        this.loading=false;
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }

  delete(value){
    console.log(value);
    let url=host+"/main/merchantConnectMaint/del";
    let model='id='+value;
    this.heroService.post(url,model).then(result=>{
        console.log(result.code);
        if(result.code==0){
          this.message.success('删除成功！');
          this.getTenantlist();
        }else{
          this.message.success(result.msg);
        }
    })
  }

  //区域管理
  setArea(id){
    this.isVisible=true;
    this.childValue=id;
  }
  handleCancel(){
    this.isVisible=false;
  }
  //重新邀请
  inviteAgain(id){
    let url=host+"/main/merchantConnectMaint/invite";
    let model="id="+id;
    this.heroService.post(url,model).then(result=>{
      if(result.code==0){
        this.message.success("重新邀请成功");
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }

  //分页
  PageIndexChange(event){
    this.PageIndex=event;
    this.getTenantlist();
  }

  //导出Excel
  exportOut() {
    const token = this.storageService.getItem("token");
    window.location.href = host + "/main/merchantConnectMaint/excelExport?token="+token+"&nameLike="+this.name+"&mobileLike="+this.mobile+"&isJoinOrg="+this.isJoinOrg+"&Status="+this.status+"&type="+this.type;
  }
}
